package com.ha7419x.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.Charset;
import java.util.Base64;

@Configuration
public class RestConfig {

    @Bean
    public HttpHeaders getHeaders(){
        HttpHeaders headers = new HttpHeaders();
        String auth = "admin:123456"; //security 认证信息
        byte[] bytes = Base64.getEncoder().encode(auth.getBytes(Charset.forName("US-ASCII")));
        //加密的信息 要和 basic 只有有個 空格 不然会报错
        String authHeader = "Basic " + new String(bytes);
        headers.set("Authorization", authHeader);
        return headers;
    }

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}
